package com.caine.androidtask.ls11;

/**
 @author : CaineZhu
 @date : 2013-01-15 13:22:46
 @desc  : for command  *#*#935#*#* *#*#66#*#* *#*#38#*#* *#*#945#*#*

 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.caine.androidtask.R;
import com.caine.androidtask.launcher.Utils;

public class Register extends Activity {
	private EditText userName;
	private EditText userPassWord;
	private Button mRegister;
	private Button mCancel;

	// private static final int RESQUESTCODE = 0X0001;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setTitle("Register...");
		setContentView(R.layout.caine_ls11_register);
		init();
         
	}

	void init() {
		userName = (EditText) findViewById(R.id.ls11_register_name);
		userPassWord = (EditText) findViewById(R.id.ls11_register_password);
		mRegister = (Button) findViewById(R.id.ls11_register_register);
		mCancel = (Button) findViewById(R.id.ls11_register_cancel);

		mRegister.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String uname = userName.getText().toString().trim();
				String upwd = userPassWord.getText().toString().trim();
				if(uname.equals("")){
					Utils.showMsg(Register.this, "Please enter username!");
					return;
				}
				if(upwd.equals("")){
					Utils.showMsg(Register.this, "Please enter password!");
					return;
				}
					
				Intent intent = new Intent(Register.this, Ls11.class);
				Bundle bundle = new Bundle();
				bundle.putString("username", uname);
				bundle.putString("userpassword", upwd);
				intent.putExtra("Ls11_bundle", bundle);
				setResult(Ls11.RESQUESTCODE, intent);
				if(Utils.DEBUG){
				System.out.println("userName.getText().toString()===>"
						+ userName.getText().toString());
				System.out.println("userPassWord.getText().toString()===>"
						+ userPassWord.getText().toString());
				System.out.println("startActivityForResult......");
				}
				Intent i = new Intent("com.caine.androidtask.START_RECEIVER");
				sendBroadcast(i);
				finish();
			}
		});
		mCancel.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// userName.setText("");
				// userPassWord.setText("");
				Intent i = new Intent("com.caine.androidtask.STOP_RECEIVER");
				sendBroadcast(i);
				finish();
			}
		});
	}

	// @Override
	// protected void onActivityResult(int requestCode, int resultCode, Intent
	// data) {
	// // TODO Auto-generated method stub
	// super.onActivityResult(requestCode, resultCode, data);
	// if (requestCode == RESQUESTCODE && resultCode == Activity.RESULT_OK) {
	// Bundle bundle = data.getExtras();
	// userName.setText(bundle.getString("username"));
	// userPassWord.setText(bundle.getString("userpassword"));
	// }
	// }
}
